package com.h2n.framework.dao.classes;

import com.h2n.framework.dao.IGroupDAO;
import com.h2n.framework.dto.GroupDTO;
import com.h2n.utils.Convert;
import com.h2n.utils.EDatetimeFormat;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by IntelliJ IDEA.
 * User: NhatNV
 * Date: Sep 23, 2009
 * Time: 11:25:55 PM
 * To change this template use File | Settings | File Templates.
 */
public class GroupDAO implements IGroupDAO {
  private JdbcTemplate jdbcTemplate;
  public JdbcTemplate getJdbcTemplate(){
    return jdbcTemplate;
  }
  public void setJdbcTemplate(JdbcTemplate _jdbcTemplate){
    jdbcTemplate = _jdbcTemplate;
  }

  @Override
  public long insert(GroupDTO _groupDto) throws Exception {
    return 0;  //To change body of implemented methods use File | Settings | File Templates.
  }

  @Override
  public void update(GroupDTO _groupDto) throws Exception {
    //To change body of implemented methods use File | Settings | File Templates.
  }

  @Override
  public void delete(int _id) throws Exception {
    //To change body of implemented methods use File | Settings | File Templates.
  }

  @Override
  public GroupDTO getInfo(int _id) throws Exception {
    GroupDTO obj = null;
    jdbcTemplate.setResultsMapCaseInsensitive(true);
    SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName(GroupDTO.GET_INFO_PROCEDURE);
    MapSqlParameterSource inParams = new MapSqlParameterSource(GroupDTO.Parameters.p_id.toString(),_id);
    Map outParams = simpleJdbcCall.execute(inParams);
    if(outParams != null){
      obj = new GroupDTO();
      obj.setId(_id);
      obj.setGroup_Name(outParams.get(GroupDTO.Parameters.p_group_name.toString()).toString());
      obj.setDescription(outParams.get(GroupDTO.Parameters.p_description.toString()).toString());
    }

    return obj;
  }

  @Override
  public List<GroupDTO> getAll() throws Exception {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
  }
}
